package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.Result;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CategoryMapper {

    /**
     * 分页查询
     * @param categoryPageQueryDTO
     * @return
     */
    Page pageQueryCategory(CategoryPageQueryDTO categoryPageQueryDTO);

    /**
     * 新增管理分类
     *
     * @param category
     */
    @Insert("insert into category(type, name, sort, status, create_time, update_time, create_user, update_user)" +
            " VALUES" +
            " (#{type}, #{name}, #{sort}, #{status}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser})")
    void addCategory(Category category );


    /**
     * 根据ID删除分类
     * @param id
     */
    @Delete("delete from category where id = #{id}")
    void deleteByCategoryID(Integer id);

    /**
     * 修改分类名称
     *
     * @param category
     * @return
     */
    void updateCategory(Category category);

    /**
     * 根据type得到菜品列表
     * @param type
     * @return
     */
    List<Category> getCategoryList(Integer type);

    /**
     * 分类名
     * @param categoryId
     * @return
     */
    @Select("select name from category where id = #{categoryId}")
    String getByID(Long categoryId);
}
